package com.atguigu1.core.operator

import org.apache.hadoop.hive.ql.exec.persistence.HybridHashTableContainer.HashPartition
import org.apache.spark.rdd.RDD
import org.apache.spark.{HashPartitioner, SparkConf, SparkContext}

/**
 *
 * @description: key,value类型rdd特定算子
 * @time: 2021-03-12 11:45
 * @author: baojinlong
 **/
object Spark18PartitionBy {
  def main(args: Array[String]): Unit = {
    val conf: SparkConf = new SparkConf().setMaster("local[*]").setAppName("rdd")
    // 设置rdd分区数字
    val sparkContext = new SparkContext(conf)
    // 排序后分区数量不变 hash range分区 python分区是私有的
    val rddValue1: RDD[Int] = sparkContext.makeRDD(Seq(1, 2, 3, 4), 2)
    val mapRdd: RDD[(Int, Int)] = rddValue1.map((_, 1))
    mapRdd.partitionBy(new HashPartitioner(2)).saveAsTextFile("output")


    sparkContext.stop()
  }
}
